package com.no1.controller.admin;

import com.no1.dao.FunctionDao;
import com.no1.entity.Function;
import com.no1.entity.Worker;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "MainController",urlPatterns = "/user/main")
public class MainController extends HttpServlet {
    private FunctionDao fd = new FunctionDao();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Worker w = (Worker) request.getSession().getAttribute("user");
        List<Function> fucntions = fd.getFun(w.getRid());
        request.setAttribute("functions",fucntions);
        request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request,response);
    }
}
